Ext.define('A4.controller.desktop.UserManagerController',{
	extend:'Ext.app.Controller',
	views:[
		'A4.view.desktop.usermanager.CreateUserView',
		'A4.view.desktop.usermanager.EditUserView'
	],
	init:function(){
		this.control({
			
			//创建用户
			'button[id=user-manager-create-user]':{
				click:function(){
					Ext.create('A4.view.desktop.usermanager.CreateUserView');
				}
			},
			
			//更新用户
			'button[id=update-manager-create-user]':{
				click:function(){
					Ext.create('A4.view.desktop.usermanager.EditUserView');
				}
			},
			
			'button[id=user-manager-delete-user]':{
				click:function(){
				  var record = Ext.getCmp('user-manager-user-list').getSelectionModel().getSelection();
				  
				  if (record.length == 0)
				  {
					  Ext.MessageBox.show('提示', '请选择您要操作的行！'); 
				  }
				  else
				  {
					  Ext.Msg.confirm('请确认','是否真的要删除数据',function(button,text){
						  if (button == 'yes')
						  {
							  var userIds = "";
							  
							  for (var i = 0;i < record.length;i++)
							  {
								  userIds += record[i].get("userId");
								  if (i < record.length - 1)
								  {
									  userIds = userIds + ',';
								  }
							  }
							  
							  Ext.Ajax.request({
								    method: 'post',
									url: '/a4/user/delete.do',
									params: {userIds: userIds},
									success:function(resp){
										var obj=Ext.decode(resp.responseText);
										
										if(obj.result == 'success') {
											Ext.MessageBox.alert('提示', '删除成功！');
										}
										else {
											Ext.MessageBox.alert('报错了！！！', '删除失败！！！' + obj.info);
										}
									}
							  });
						  }
					  });
				  }
			   }
			},
			
			//创建用户完成
			'button[id=create-user-finsh]':{
				click:function(){
				
				  /* var record = Ext.getCmp('create-user-role-grid').getSelectionModel().getSelection(); 
				   
				   var roleIds = "";
				  
				   if (record.length != 0)
				   {
					   for (var i = 0;i < record.length;i++)
					   {
						   roleIds += record[i].get("roleId");
						   if (i < record.length - 1)
						   {
							   roleIds = roleIds + ',';
						   }
					   }
				   }*/
				   
				 
				 var form = Ext.getCmp('create-user-form').getForm(); 
				 
				 
				 form.doAction('submit', {
						url: '/a4/user/insert.do',
						method: 'post',
						waitTitle:'请等待',
						waitMsg: '正在提交...',
						params: '',
						success: function(form, action) {
							if(action.result.result == 'success') {
								Ext.MessageBox.alert('结果', '保存成功！');
							}
						}
					});
				  
				}
			}
		});
	}
});